<?php
if(!defined('MY_ROOT'))
{
throw new Exception('Access Denied');
}
class MAIL{
public static $driver;
public static $config;
public static function init($config)
{
switch($config['method'])
{
case 1:
self::$driver='mail';
break;
case 2;
self::$driver='smtp';
break;
default:
self::$driver='mail';
break;
}
self::$config=$config;
}
private static function send($to,$title,$content)
{
if(self::$driver=='mail')
{
self::_mail($to,$title,$content);
}elseif(self::$driver=='smtp')
{
//self::_smtp($to,$title,$content);
}
}
private static function _mail($to,$title,$content)
{
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
$headers .= 'From: <'.self::$config['from'].'>' . "\r\n";
mail($to,$title,$content,$headers);
}
public static function forgetpass($email,$sid,$hash)
{
$content=file_get_contents(MY_ROOT."/data/mail/forgetpass.html");
$content=str_replace('{sid}',$sid,$content);
$content=str_replace('{hash}',$hash,$content);
$t=DB::select('settings',"`catalog`='mail_forgetpass'",'`id`',true);
$title=$t['value'];
self::send($email,$title,$content);
}
public static function welcome($email,$user)
{
$content=file_get_contents(MY_ROOT."/data/mail/welcome.html");
$content=str_replace('{username}',$user,$content);
$t=DB::select('settings',"`catalog`='mail_welcome'",'`id`',true);
$title=$t['value'];
self::send($email,$title,$content);
}
}
?>
